﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class cn_news : System.Web.UI.Page
{
    protected string _cid = "";
    protected string  mode="";
    protected void Page_Load(object sender, EventArgs e)
    {
        Control ctr = null;
         mode = Request.QueryString["mode"];
        switch (mode)
        {
            case "baiy": ctr = this.LoadControl("common/menu_baiy.ascx"); break;
            case "about": ctr = this.LoadControl("common/menu_about.ascx"); break;
            case "ztactive": ctr = this.LoadControl("common/menu_ztactive.ascx"); break;
            case "jnews": ctr = this.LoadControl("common/menu_jnews.ascx"); break;
            case "pxnews": ctr = this.LoadControl("common/menu_pxnews.ascx"); break;
            case "kfu": ctr = this.LoadControl("common/menu_kfu.ascx"); break;
            case "kgarden": ctr = this.LoadControl("common/menu_kgarden.ascx"); break;
            case "index": ctr = this.LoadControl("common/menu_index.ascx"); break;
            case "user": ctr = this.LoadControl("common/menu-index.ascx");
                menu_file1.Visible = false;   // panne2.Visible = false;
                break;
            default: ctr = this.LoadControl("common/menu_news.ascx"); break;
        }

        panne1.Controls.Add(ctr);

        _cid = Request.QueryString["cid"];
        if (string.IsNullOrEmpty(_cid))
        {
            _cid = ColumnHelp.GetFirstColumnId(4);
        }
        else
        {
            if (!Whir.Common.WebHelper.Utils.IsInt(_cid))
                _cid = ColumnHelp.GetFirstColumnId(4);
        }

        //Control str2 = null;
        //if (string.IsNullOrEmpty(Request.QueryString["cid"]) || _cid == "12" || _cid == "13")
        //{
        //    str2 = this.LoadControl("common/menu_leftnews2.ascx");
        //}
        //else
        //{
        //    str2 = this.LoadControl("common/menu_leftnews2.ascx");
        //   // str2 = this.LoadControl("common/menu_file.ascx");
        //}
        //panne2.Controls.Add(str2);


        if (!IsPostBack)
        {
            GetTipsInfo();
            GetList();
        }
    }

    private void GetTipsInfo()
    {
        ltrTips.Text = ColumnHelp.GetColumnName(_cid);
    }

    private void GetList()
    {
        string url = string.Format("about.aspx?cid={0}&mode=news", _cid);
        ColumnHelp.getReader(_cid, url, ColumnHelp.ModuleMarkMode.SinglePage);
        string id = "";
        string sql = "SELECT top 1 * FROM Whir_U_News WHERE IsTop='是' and UploadImg<>'' and TypeID=" + _cid + " order by CreateDate desc";
        DataTable dtAudit = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dtAudit != null && dtAudit.Rows.Count > 0)
        {
            id = dtAudit.Rows[0]["Whir_U_News_PID"].ToString();
            rptAuditList.DataSource = dtAudit;
            rptAuditList.DataBind();
        }


        AspNetPager1.PageSize = 15;
        string where = "TypeID=" + _cid;
       
        if (!string.IsNullOrEmpty(id))
        {
            where += " and Whir_U_News_PID<>" + id;
        }
        string countSql = "SELECT COUNT(*) FROM Whir_U_News WHERE " + where;
        AspNetPager1.RecordCount = int.Parse(Whir.SQLServerDAL.DbHelperSQL.GetSingle(countSql).ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.GetList("Whir_U_News", "Whir_U_News_PID", "*", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex - 1, where, "", "CreateDate desc").Tables[0];
        rptList.DataSource = dt;
        rptList.DataBind();


        

    }

    protected void AspNetPager1_PageChanged1(object sender, EventArgs e)
    {
        GetList();
    }
}
